package com.zjdiepu.www.rest.api.third;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.net.SocketTimeoutException;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.lang.HttpClientException;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.ibiz.third.IPhoneNumberAddrService;
import com.zjdiepu.www.model.third.request.AddressByPhoneNumberRequest;
import com.zjdiepu.www.model.third.response.CarModelResponse;
@RestController
@RequestMapping(value= "PhoneNumberAddrController", produces="application/json;charset=UTF-8")
@Api(tags = {"手机号码归属地查询"}, produces="application/json;charset=UTF-8")
public class PhoneNumberAddrController extends BaseController{

	@Resource
	private IPhoneNumberAddrService iPhoneNubmerAddrService;
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: getAddressByPhoneNumber <br/>
	 * @Description: 手机归属地获取 <br/>
	 * @param carModelRequest
	 * @return
	 * @version V1.0 <br/>
	 */
	@ApiOperation(value = "手机归属地获取", response = CarModelResponse.class, httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue = "ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
			@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue = "Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String") })
	@RequestMapping("getAddressByPhoneNumber")
	public ApiResponse getAddressByPhoneNumber(@Validated @RequestBody AddressByPhoneNumberRequest addressByPhoneNumberRequest){
		
		Map<String,Object> map=null;
		try {
			map = iPhoneNubmerAddrService.getAddressByPhoneNumber(addressByPhoneNumberRequest.getPhoneCode());
		} catch (SocketTimeoutException | HttpClientException e) {
			e.printStackTrace();
		}
		
		return ApiResponse.success(map);
	}
}
